﻿layui.use(['form', 'laydate'],
    function () {
        var $ = layui.$;
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        laydate.render({
            elem: '#date'
        });
        function RestEmployee() {
            $(".layui-form").reset();
            form.render();
        };
        // 提交事件
        form.on('submit(demo1)', function (data) {
            var field = data.field;
            console.log(field);
            $.post({
                url: "http://10.31.60.18:8000/AuthorizationSetRout/api/Department/DepartmentCreate",
                data: JSON.stringify(field),
                contentType: "application/json",
                success: res => {
                    if (res > 0) {
                        var icon = 0;
                        layer.alert('添加成功', {
                            icon: 1,
                            shadeClose: true,
                            title: "部门新增",
                        }, function () {
                            location.href = "/Department/DepartmentList";
                        });
                    } else {
                        layer.msg('添加失败：');
                    }
                },
                error: function () {
                    // 请求失败的处理
                    layer.msg('请求失败，请重试');
                }
            });
            // 阻止表单默认提交
            return false;
        });
    })